﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Sales_DrawPrint : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           
                ZSql zsql = new ZSql();
                hfgetid.Value = Server.UrlDecode(Request.Cookies["user"].Values["realname"]);
                string WageId = Request.QueryString["WageId"].ToString();
                

                if (WageId == "All")
                {
                    string sql = "select WagesId,WStaffId,WStaffName,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditUserName,convert(char(10),AuditDate,120) as AuditDate,department from CS_Wages order by WagesId desc  ";
                    zsql.Open(sql);
                }
                if (WageId == "tj")
                {
                    string gettim1 = Request.QueryString["gettim1"].ToString();
                    string gettim2 = Request.QueryString["gettim2"].ToString();
                    string name = Request.QueryString["name"].ToString();
                    string selectId = Request.QueryString["selectId"].ToString();
                    if (gettim1!=""&&gettim2!="")
                    {

                        string sql = "select WagesId,WStaffId,WStaffName,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditUserName,convert(char(10),AuditDate,120) as AuditDate,department from CS_Wages where convert(char(10),AuditDate,120) >='" + gettim1 + "' and convert(char(10),AuditDate,120) <='" + gettim2 + "' order by WagesId desc  ";
                        zsql.Open(sql);
                    }
                    if (name!="")
                    {

                        string sql = "select WagesId,WStaffId,WStaffName,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditUserName,convert(char(10),AuditDate,120) as AuditDate,department from CS_Wages where WStaffName='" + name + "'  order by WagesId desc  ";
                        zsql.Open(sql);
                    }
                    if (selectId != "0")
                    {
                        string sql = "select WagesId,WStaffId,WStaffName,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditUserName,convert(char(10),AuditDate,120) as AuditDate,department,Deptname from CS_Wages,Department where Deptid=" + selectId + " and Department=Deptname order by WagesId desc  ";
                        zsql.Open(sql);
                    }
                    if (gettim1 != "" && gettim2 != "" && name != "")
                    {
                        string sql = "select WagesId,WStaffId,WStaffName,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditUserName,convert(char(10),AuditDate,120) as AuditDate,department from CS_Wages where convert(char(10),AuditDate,120) >='" + gettim1 + "' and convert(char(10),AuditDate,120) <='" + gettim2 + "' and WStaffName='" + name + "' order by WagesId desc  ";
                        zsql.Open(sql);
                    
                    }
                    if (gettim1 != "" && gettim2 != "" && selectId != "0")
                    {
                        string sql = "select WagesId,WStaffId,WStaffName,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditUserName,convert(char(10),AuditDate,120) as AuditDate,department,Deptname from CS_Wages,Department where Deptid=" + selectId + " and Department=Deptname and convert(char(10),AuditDate,120) >='" + gettim1 + "' and convert(char(10),AuditDate,120) <='" + gettim2 + "' order by WagesId desc  ";
                        zsql.Open(sql);
                    }
                    if (selectId != "0" && name != "")
                    {
                        string sql = "select WagesId,WStaffId,WStaffName,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditUserName,convert(char(10),AuditDate,120) as AuditDate,department,Deptname from CS_Wages,Department where Deptid=" + selectId + " and Department=Deptname and WStaffName='" + name + "' order by WagesId desc  ";
                        zsql.Open(sql);
                    }
                    if (gettim1 != "" && gettim2 != "" && name != "" && selectId != "0")
                    {
                        string sql = "select WagesId,WStaffId,WStaffName,comodName,modul,WStaffSalary,WStaffPrice,WStaffPercentage,WStaffPerformance,WYWage,WSWage,WDiscount,WageDate,AuditUserName,convert(char(10),AuditDate,120) as AuditDate,department,Deptname from CS_Wages,Department where Deptid=" + selectId + " and Department=Deptname and WStaffName='" + name + "' and convert(char(10),AuditDate,120) >='" + gettim1 + "' and convert(char(10),AuditDate,120) <='" + gettim2 + "'  order by WagesId desc  ";
                        zsql.Open(sql);
                    }
                }
                
                DataTable dt = new DataTable();
                string strTable = "";
                dt = zsql.m_table;
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        strTable += "<div align=\"center\" style=\"width: 97%; font-size: 24px; font-weight: bolder; margin-bottom: 7px;\">员工工资单</div>";
                        strTable += "<table style=\"width: 97%;text-align:center;\" class=\"normal\">";

                        strTable += "<tr height=\"10\"><td width=\"11%\">员工姓名</td><td width=\"9%\">所属部门</td><td width=\"9%\">基本工资</td><td width=\"9%\">员工奖金</td><td width=\"9%\">员工提成</td><td width=\"10%\">员工业绩</td><td width=\"10%\">应发工资</td><td width=\"9%\">扣除工资</td> <td width=\"9%\">实发工资</td><td width=\"10%\">业绩日期</td></tr>";
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                           

                            strTable += "<tr><td>" + zsql.m_table.Rows[i]["WStaffName"].ToString() + "</td><td>" + zsql.m_table.Rows[i]["department"].ToString() + "</td><td>" + zsql.m_table.Rows[i]["WStaffSalary"].ToString().Substring(0, zsql.m_table.Rows[i]["WStaffSalary"].ToString().Length - 2) + "</td><td>" + zsql.m_table.Rows[i]["WStaffPrice"].ToString().Substring(0, zsql.m_table.Rows[i]["WStaffPrice"].ToString().Length - 2) + "</td><td>" + zsql.m_table.Rows[i]["WStaffPercentage"].ToString() + "%</td><td>" + zsql.m_table.Rows[i]["WStaffPerformance"].ToString().Substring(0, zsql.m_table.Rows[i]["WStaffPerformance"].ToString().Length - 2) + "</td><td>" + zsql.m_table.Rows[i]["WYWage"].ToString().Substring(0, zsql.m_table.Rows[i]["WYWage"].ToString().Length - 2) + "</td><td>" + zsql.m_table.Rows[i]["WDiscount"].ToString().Substring(0, zsql.m_table.Rows[i]["WDiscount"].ToString().Length - 2) + "</td><td>" + zsql.m_table.Rows[i]["WSWage"].ToString().Substring(0, zsql.m_table.Rows[i]["WSWage"].ToString().Length-2) + "</td><td>" + zsql.m_table.Rows[i]["WageDate"].ToString() + "</td></tr>";

                            strTable += "<tr><td>所卖商品：</td><td colspan=\"3\">" + zsql.m_table.Rows[i]["comodName"].ToString() + "</td><td colspan=\"4\"></td><td>类型：</td><td>" + zsql.m_table.Rows[i]["modul"].ToString() + "</td></tr>";


                        }
                    }
                }
                strTable += "</table>";
                strTable += "<table style=\"width: 97%;text-align:center;\" class=\"normal\"><tr><td width=\"155px\">操作时间：</td><td width=\"332px\">" + DateTime.Now.ToString() + "</td><td width=\"131px\">操作员：</td><td>" + hfgetid.Value + "</td></tr></table>";
                zsql.Close();
                lblTable.Text = strTable;
           
        }
    }
}
